package com.hellogood.yaohuo.client.bussiness.pandian;

import java.util.LinkedHashMap;
import java.util.List;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.hellogood.yaohuo.client.bussiness.SearchController;
import com.hellogood.yaohuo.client.common.SearchResultAsynCallback;
import com.hellogood.yaohuo.shared.entity.Org;
import com.hellogood.yaohuo.shared.services.OrgService;
import com.hellogood.yaohuo.shared.services.PandianService;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.grid.ListGridField;

public class PandianSearchController extends SearchController {

	@Override
	public void searchForm(String orgCode, String startDate, String endDate, String rz) {
		PandianService.Util.getInstance().searchPandianFormByOrgCodeAndDate(orgCode, 0, startDate, endDate, rz, new SearchResultAsynCallback(listGrid));
	}

	@Override
	protected void initData() {
		OrgService.Util.getInstance().getCOrgListByStaffCode(new AsyncCallback<List<Org>>() {

			@Override
			public void onSuccess(List<Org> result) {
				if (result != null) {
					LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
					for (Org o : result) {
						map.put(o.getOrgCode(), o.getOrgCode() + "-" + o.getOrgName());
						orgItem.setValueMap(map);
					}
					if (result.size() > 0) {
						orgItem.setValue(result.get(0).getOrgCode());
					}
				}
			}

			@Override
			public void onFailure(Throwable caught) {
				SC.say(caught.getMessage());
			}
		});
	}

	protected void buildListFields() {
		fields = new ListGridField[] { codeField, orgField, dateField, amountField, zdUserField, zdDateField, rzDateField, statusField, remarkField };
	}

}
